<?php
/**
 * 一间咖啡馆后台管理员
 * Created by PhpStorm.
 * User: sunzexin
 * Date: 2018/1/10
 * Time: 09:56
 */

namespace App\Http\Logics\MiniProgram;


use App\Admin;
use Illuminate\Support\Facades\Redis;
use App\Http\Logics\BaseLogic;

class AdminLogic extends BaseLogic
{
    public static function login($data)
    {
        try {
            if (Admin::where('email', $data['email'])->count()) {
                if (Admin::where('email', $data['email'])->where('password', md5($data['password']))->count()) {
                    $admin = Admin::where('email', $data['email'])->where('password', md5($data['password']))->first();
                    Redis::set(md5($admin->id), md5($admin->password));
                    return self::response(self::SUCCESS, md5($admin->id));
                } else {
                    return self::response(self::ACCOUNT_OR_PASSWORD_IS_WRONG);
                }
            } else {
                return self::response(self::ACCOUNT_OR_PASSWORD_IS_WRONG);
            }
        }catch (\Exception $e){
            return self::response(self::SYSTEM_ERROR);
        }
    }
}